<template> 
	<div class="JNPF-common-layout">
		<div class="JNPF-common-layout-center">
			<!-- <el-row class="JNPF-common-search-box" :gutter="16">
				<el-form @submit.native.prevent>
					<el-col :span="6">
						<el-form-item label="风险点ID">
							<el-input v-model="query.fxdid" placeholder="风险点ID" clearable  />
						</el-form-item>
					</el-col>
					<el-col :span="6">
					<el-form-item>
						<el-button type="primary" icon="el-icon-search" @click="search()">查询</el-button>
						<el-button icon="el-icon-refresh-right" @click="reset()">重置</el-button>
					</el-form-item>
					</el-col>
				</el-form>
			</el-row> -->
			<div class="JNPF-common-layout-main JNPF-flex-main">
				<div class="JNPF-common-head">
					<div>
						<!-- <el-button type="primary" icon="el-icon-plus" @click="addOrUpdateHandle()">
							新增
						</el-button> -->
                        <el-button type="text" @click="goFanHui1()">
							返回
						</el-button>
					</div>
					<div class="JNPF-common-head-right">
						<el-tooltip effect="dark" content="刷新" placement="top">
							<el-link icon="icon-ym icon-ym-Refresh JNPF-common-head-icon" :underline="false"  @click="reset()" />
						</el-tooltip>
						<screenfull :isContainer="true" />
						<el-tooltip effect="dark" content="列设置" placement="top">
							<el-link icon="icon-ym icon-ym-options JNPF-common-head-icon" :underline="false" />
						</el-tooltip>
					</div>
				</div>
				<JNPF-table v-loading="listLoading" :data="list">
					<el-table-column label="风险点类型"  prop="fxdlx" algin="left">
						<template slot-scope="scope">{{ scope.row.fxdlx | dynamicText(fxdlxOptions) }}</template>
					</el-table-column>
					<!-- <el-table-column prop="fxdmc" label="风险点名称" align="left" /> -->
                    <template v-if="lx=='设备设施'">
                        <div>
                            <el-table-column prop="jcxm" label="检查项目" align="left" />
                            <el-table-column prop="jcbz" label="检查标准" align="left" />
                            <el-table-column prop="bfhbzqk" label="不符合标准情况" align="left" />
                            <el-table-column prop="zyhg" label="主要后果" align="left" />
                        </div>
                    </template>
                    <template v-if="lx=='作业活动'">
                        <div>
                            <el-table-column prop="zybz" label="作业步骤" align="left" />
                            <el-table-column prop="wxyhqzsj" label="危险源或潜在事件" align="left" />
					        <el-table-column prop="knfsdsjlxjhg" label="可能发生的事故类型及后果" align="left" />
                        </div>
                    </template>
                    <template v-if="lx=='工艺节点'">
                        <div>
                            <el-table-column prop="jd" label="节点" align="left" />
                            <el-table-column prop="cs" label="参数" align="left" />
                            <el-table-column prop="csms" label="参数描述" align="left" />
                            <el-table-column prop="ydc" label="引导词" align="left" />
                            <el-table-column prop="pc" label="偏差" align="left" />
                            <el-table-column prop="knyy" label="可能原因" align="left" />
                            <el-table-column prop="zyhg" label="主要后果" align="left" />
                        </div>
                    </template>
					<!-- <el-table-column label="状态"  prop="zt" algin="left">
						<template slot-scope="scope">{{ scope.row.zt | dynamicText(ztOptions) }}</template>
					</el-table-column> -->
					<!-- <el-table-column prop="fxdid" label="风险点ID" align="left" /> -->
					<el-table-column label="操作" fixed="right" width="150">
						<template slot-scope="scope">
                            <el-button type="text" v-if="scope.row.zt == ''" @click="normal(scope.row.id)" >
								正常
							</el-button>
                            <el-button type="text" v-else-if="scope.row.zt == 0" style="color:#ccc;cursor:not-allowed;">
								正常
							</el-button>
                            <el-button type="text" v-if="scope.row.zt == ''" @click="addOrUpdateHandle(scope.row.id,false,scope.row.fxdlx)" >
								隐患登记
							</el-button>
                            <el-button type="text" v-else-if="scope.row.zt == 1" style="color:#ccc;cursor:not-allowed;">
								隐患登记
							</el-button>
						</template>
					</el-table-column>
				</JNPF-table>
				<pagination :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="initData" />
			</div>
		</div>
		<JNPF-Form v-if="formVisible" ref="JNPFForm" @refresh="refresh" />
		<ExportBox v-if="exportBoxVisible" ref="ExportBox" @download="download" />
	</div>

</template> 
<script>
    import request from '@/utils/request'
    import {getDictionaryDataSelector} from '@/api/systemData/dictionary'
    import JNPFForm from './FormJcx'
    import ExportBox from './ExportBox'
    import {previewDataInterface} from '@/api/systemData/dataInterface'

    export default {
        components: {JNPFForm, ExportBox},
        data() {
            return {
                lx: '',
                    showAll: false,
                query: {
					fxdid:undefined,

                },
                defaultProps: {
                    children: 'children',
                    label: 'fullName'
                },
                list: [],
                listLoading: true,
                total: 0,
                listQuery: {
					// currentPage: 1,
					// pageSize: 20,
                    page: 1,
					limit: 20,

                    sort: "desc",
                    sidx: "",
                },
                formVisible: false,
                exportBoxVisible: false,
                columnList: [
					{prop: 'fxdlx', label: '风险点类型'},
					{prop: 'fxdmc', label: '风险点名称'},
					{prop: 'jcxm', label: '检查项目'},
					{prop: 'jcbz', label: '检查标准'},
					{prop: 'bfhbzqk', label: '不符合标准情况'},
					{prop: 'wxyhqzsj', label: '危险源或潜在事件'},
					{prop: 'knfsdsjlxjhg', label: '可能发生的事故类型及后果'},
					{prop: 'jd', label: '节点'},
					{prop: 'cs', label: '参数'},
					{prop: 'csms', label: '参数描述'},
					{prop: 'ydc', label: '引导词'},
					{prop: 'pc', label: '偏差'},
					{prop: 'knyy', label: '可能原因'},
					{prop: 'zyhg', label: '主要后果'},
					{prop: 'zt', label: '状态'},
					{prop: 'fxdid', label: '风险点ID'},

                ],
				fxdlxOptions:[{"fullName":"设备设施","id":"设备设施"},{"fullName":"作业活动","id":"作业活动"},{"fullName":"工艺节点","id":"工艺节点"}],
				ztOptions:[{"fullName":"正常","id":"0"},{"fullName":"隐患登记","id":"1"}],


            }
        },
        computed: {},
        created() {
        },
        methods: {


            initData(Id,fxdlx) {
                this.listLoading = true;
                this.query.fxdid = Id;
                this.lx = fxdlx;
                let query = {
                    ...this.listQuery,
                    ...this.query
                };
                request({
                    url: `/api/System/pcjh/Actions/FXDJCX`,
                    method: 'post',
                    data: query
                }).then(res => {
                   let list = JSON.parse(res.msg);
                   this.list = list.data;
                   this.listLoading = false
                    // this.$nextTick(() => {
                    //     this.tableHeight = "100%"
                    // });
                })
            },
            handleDel(id) {
                this.$confirm('此操作将永久删除该数据, 是否继续?', '提示', {
                    type: 'warning'
                }).then(() => {
                    request({
                        url: `/api/system/pcjhfxdjcx/${id}`,
                        method: 'DELETE'
                    }).then(res => {
                        this.$message({
                            type: 'success',
                            message: res.msg,
                            onClose: () => {
                                this.initData(this.query.fxdid,this.lx)
                            }
                        });
                    })
                }).catch(() => {
                });
            },
            addOrUpdateHandle(id,isDetail,fxdlx) {
                this.formVisible = true
                this.$nextTick(() => {
                    this.$refs.JNPFForm.init(id,isDetail,fxdlx)
                })
            },
            exportData() {
                this.exportBoxVisible = true
                this.$nextTick(() => {
                    this.$refs.ExportBox.init(this.columnList)
                })
            },
            download(data) {
                let query = {...data, ...this.listQuery, ...this.query}
                request({
                    url: `/api/system/pcjhfxdjcx/Actions/Export`,
                    method: 'POST',
                    data: query
                }).then(res => {
                    if (!res.data.url) return
                    window.location.href = this.define.comUrl + res.data.url
                    this.$refs.ExportBox.visible = false
                    this.exportBoxVisible = false
                })
            },
            search() {
                this.listQuery = {
					page: 1,
					limit: 20,

                    sort: "desc",
                    sidx: "",
                }
                this.initData(this.query.fxdid,this.lx)
            },
            refresh() {
                this.formVisible = false
                // if (isrRefresh) this.reset()
                this.initData(this.query.fxdid,this.lx)
            },
            reset() {
                // for (let key in this.query) {
                //     this.query[key] = undefined
                // }
                this.listQuery = {
					page: 1,
					limit: 20,

                    sort: "desc",
                    sidx: "",
                }
                this.initData(this.query.fxdid,this.lx)
            },
             goFanHui1(){
                this.$emit("refreshIndexJcx", '');
            },
            normal(Id){
                let query = {
                    id: Id,
                    zt: '0'
                }
                request({
                    url: '/api/System/pcjh/Actions/JCXZT',
                    method: 'POST',
                    data: query
                }).then((res) =>{
                    this.$message({
                        message: res.msg,
                        type: 'success',
                        duration: 1000,
                        onClose: () =>{
                            this.initData(this.query.fxdid,this.lx)
                        }
                    })

                })
            }
        }
    }
</script>